package com.fc.redis.service;

import com.fc.redis.entity.TbUser;
import com.fc.redis.mapper.TbUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created By gao_e on 2020/3/29 13:58
 */
@Service
public class UserService2 /*implements IUserService*/ {
    @Autowired
    private TbUserMapper tbUserMapper;
    // 自己注入自己
    @Autowired
    private UserService2 userService2;
    public void addUserTest() {
        System.out.println(this.getClass());
        System.out.println(userService2);
        System.out.println(userService2.getClass());
        System.out.println(this == userService2);
        // do something
        // 这里改用注入的IOC中的userService2调用添加了事务的方法
//        userService2.addUsers();
        this.addUsers();
        // do something
    }
    @Transactional
    public void addUsers() {
        tbUserMapper.insert(new TbUser("传智播客"));
        int i = 1/0;
        tbUserMapper.insert(new TbUser("黑马程序员"));
    }
}
